package dreampack.dataType;

//import java.util.*;
import java.sql.*;
import java.util.Calendar;

import dreampack.*;
import dreampack.dataQuery.*;

public class MessageType {
	private int msgId;
	private String msgTitle;
	private String msgContent;
	private UserType author;
	private Timestamp createAt;
	private Timestamp lastModify;
	
	
	public MessageType() { }
	
	public boolean init(DreamDB dreamDb, ResultSet rs) throws Exception{
		boolean bRet = true;
		
		this.msgId = (int)rs.getInt("id");
		this.msgTitle = (String)rs.getString("title");
		this.msgContent = (String)rs.getString("content");
		this.author = (UserType)UserQuery.queryById(dreamDb, rs.getInt("author_id"));
		this.createAt = (Timestamp)rs.getTimestamp("create_at");
		this.lastModify = (Timestamp)rs.getTimestamp("lastmodify");
		
		return bRet;
	}
	public int getId(){
		return this.msgId;
	}
	public String getTitle(){
		return this.msgTitle;
	}
	public String getContent(){
		return this.msgContent;
	}
	public UserType getAuthor(){
		return this.author;
	}
	public java.util.Date getCreateAt(){
		java.util.Date tempDate = null;
		if (null != this.createAt) {
			Calendar cal = Calendar.getInstance();
			cal.setTimeInMillis(this.createAt.getTime());
			tempDate = cal.getTime();
		}
		return tempDate;
	}
	public java.util.Date getLastModify(){
		java.util.Date tempDate = null;
		if (null != this.lastModify) {
			Calendar cal = Calendar.getInstance();
			cal.setTimeInMillis(this.lastModify.getTime());
			tempDate = cal.getTime();
		}
		return tempDate;
	}
}
